﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CCWin;
using CRegex;
namespace weiqijiance.工位配置
{
    public partial class APSsetting : CCSkinMain
    {
        public APSsetting()
        {
            InitializeComponent();
        }

        private void APSsetting_Load(object sender, EventArgs e)
        {

            iniclass objini = new iniclass();
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\安综检仪表配置.ini";
            string path1 = string.Format(@"{0}", path);
            objini.Ini(path1);
            checkBox1.Checked = objini.ReadValue("多地沟1", "启用").Trim().Contains("是") ? true : false;
            txtdp1.Text = objini.ReadValue("多地沟1", "灯牌串口设置").Trim();
            txtsmq1.Text = objini.ReadValue("多地沟1", "扫描枪串口设置").Trim();

            checkBox2.Checked = objini.ReadValue("多地沟2", "启用").Trim().Contains("是") ? true : false;
            txtdp2.Text = objini.ReadValue("多地沟2", "灯牌串口设置").Trim();
            txtsmq2.Text = objini.ReadValue("多地沟2", "扫描枪串口设置").Trim();

            checkBox3.Checked = objini.ReadValue("多地沟3", "启用").Trim().Contains("是") ? true : false;
            txtdp3.Text = objini.ReadValue("多地沟3", "灯牌串口设置").Trim();
            txtsmq3.Text = objini.ReadValue("多地沟3", "扫描枪串口设置").Trim();

            checkBox4.Checked = objini.ReadValue("设置", "地沟显示检测时间").Trim().Contains("是") ? true : false;
            che_dpjxylx.Checked = objini.ReadValue("地沟", "增加底盘间隙仪录像").Trim().Contains("是") ? true : false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            checkcom(txtsmq1.Text, checkBox1.Checked);
            checkcom(txtsmq2.Text, checkBox2.Checked);
            checkcom(txtsmq3.Text, checkBox3.Checked);




            iniclass objini = new iniclass();
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\安综检仪表配置.ini";
            string path1 = string.Format(@"{0}", path);
            objini.Ini(path1);

            objini.Writue("多地沟1", "启用", checkBox1.Checked ? "是" : "否");
            objini.Writue("多地沟2", "启用", checkBox2.Checked ? "是" : "否");
            objini.Writue("多地沟3", "启用", checkBox3.Checked ? "是" : "否");

            objini.Writue("多地沟1", "灯牌串口设置", txtdp1.Text);
            objini.Writue("多地沟2", "灯牌串口设置", txtdp2.Text);
            objini.Writue("多地沟3", "灯牌串口设置", txtdp3.Text);


            objini.Writue("多地沟1", "扫描枪串口设置", txtsmq1.Text);
            objini.Writue("多地沟2", "扫描枪串口设置", txtsmq2.Text);
            objini.Writue("多地沟3", "扫描枪串口设置", txtsmq3.Text);

            objini.Writue("设置", "地沟显示检测时间", checkBox4.Checked ? "是" : "否");
            objini.Writue("地沟", "增加底盘间隙仪录像", che_dpjxylx.Checked ? "是" : "否");
            MessageBox.Show("完成");
            基类窗体.UploadAndDownload fupload = new 基类窗体.UploadAndDownload();
            objini.Ini(System.Windows.Forms.Application.StartupPath + "\\系统信息.ini");
            string sjcxname = objini.ReadValue("系统信息", "检测线名称");
            string sgongweiname = objini.ReadValue("系统信息", "检测工位名称");
            fupload.upload(sjcxname, sgongweiname, "安综检仪表配置.ini");
        }

        public bool checkcom(string scom,bool zt)
        {
            if (zt)
            {
                if (!CRegex.C_Regex.IsCOM(scom))
                {
                    DialogResult result = MessageBox.Show(string.Format(@"当前信号处理板形式为：{0} " + "\n\r" + "正确串口格式为:COM(X:数字):19200(波特率）:0:0:1 " + "\n\r" +
              "实例:COMx:4800:8:0:1", scom), "提示", MessageBoxButtons.OKCancel);
                    if (result == DialogResult.OK)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            return true;
        }
    }
}
